// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*!
 * @file DdsRecorderMonitoringStatusTypeObject.cpp
 * This source file contains the definition of the described types in the IDL file.
 *
 * This file was generated by the tool fastddsgen.
 */

#ifdef _WIN32
// Remove linker warning LNK4221 on Visual Studio
namespace {
char dummy;
} // namespace
#endif // ifdef _WIN32

#include <ddsrecorder_participants/common/types/monitoring/ddsrecorder_status/v1/DdsRecorderMonitoringStatus.h>
#include \
    <ddsrecorder_participants/common/types/monitoring/ddsrecorder_status/v1/DdsRecorderMonitoringStatusTypeObject.h>
#include <mutex>
#include <utility>
#include <sstream>
#include <fastdds/rtps/common/CdrSerialization.hpp>
#include <fastrtps/rtps/common/SerializedPayload.h>
#include <fastrtps/utils/md5.h>
#include <fastrtps/types/TypeObjectFactory.h>
#include <fastrtps/types/TypeNamesGenerator.h>
#include <fastrtps/types/AnnotationParameterValue.h>

using namespace eprosima::fastrtps::rtps;

void registerDdsRecorderMonitoringStatusTypes()
{
    static std::once_flag once_flag;
    std::call_once(once_flag, []()
            {
                TypeObjectFactory* factory = TypeObjectFactory::get_instance();
                factory->add_type_object("MonitoringErrorStatus", GetMonitoringErrorStatusIdentifier(true),
                GetMonitoringErrorStatusObject(true));
                factory->add_type_object("MonitoringErrorStatus", GetMonitoringErrorStatusIdentifier(false),
                GetMonitoringErrorStatusObject(false));


                factory->add_type_object("MonitoringStatus", GetMonitoringStatusIdentifier(true),
                GetMonitoringStatusObject(true));
                factory->add_type_object("MonitoringStatus", GetMonitoringStatusIdentifier(false),
                GetMonitoringStatusObject(false));


                factory->add_type_object("DdsRecorderMonitoringErrorStatus",
                GetDdsRecorderMonitoringErrorStatusIdentifier(true),
                GetDdsRecorderMonitoringErrorStatusObject(true));
                factory->add_type_object("DdsRecorderMonitoringErrorStatus",
                GetDdsRecorderMonitoringErrorStatusIdentifier(false),
                GetDdsRecorderMonitoringErrorStatusObject(false));


                factory->add_type_object("DdsRecorderMonitoringStatus", GetDdsRecorderMonitoringStatusIdentifier(true),
                GetDdsRecorderMonitoringStatusObject(true));
                factory->add_type_object("DdsRecorderMonitoringStatus", GetDdsRecorderMonitoringStatusIdentifier(false),
                GetDdsRecorderMonitoringStatusObject(false));

            });
}

const TypeIdentifier* GetDdsRecorderMonitoringErrorStatusIdentifier(
        bool complete)
{
    const TypeIdentifier* c_identifier = TypeObjectFactory::get_instance()->get_type_identifier(
        "DdsRecorderMonitoringErrorStatus", complete);
    if (c_identifier != nullptr && (!complete || c_identifier->_d() == EK_COMPLETE))
    {
        return c_identifier;
    }

    GetDdsRecorderMonitoringErrorStatusObject(complete); // Generated inside
    return TypeObjectFactory::get_instance()->get_type_identifier("DdsRecorderMonitoringErrorStatus", complete);
}

const TypeObject* GetDdsRecorderMonitoringErrorStatusObject(
        bool complete)
{
    const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object(
        "DdsRecorderMonitoringErrorStatus", complete);
    if (c_type_object != nullptr)
    {
        return c_type_object;
    }
    else if (complete)
    {
        return GetCompleteDdsRecorderMonitoringErrorStatusObject();
    }
    //else
    return GetMinimalDdsRecorderMonitoringErrorStatusObject();
}

const TypeObject* GetMinimalDdsRecorderMonitoringErrorStatusObject()
{
    const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object(
        "DdsRecorderMonitoringErrorStatus", false);
    if (c_type_object != nullptr)
    {
        return c_type_object;
    }

    TypeObject* type_object = new TypeObject();
    type_object->_d(EK_MINIMAL);
    type_object->minimal()._d(TK_STRUCTURE);

    type_object->minimal().struct_type().struct_flags().IS_FINAL(false);
    type_object->minimal().struct_type().struct_flags().IS_APPENDABLE(false);
    type_object->minimal().struct_type().struct_flags().IS_MUTABLE(false);
    type_object->minimal().struct_type().struct_flags().IS_NESTED(false);
    type_object->minimal().struct_type().struct_flags().IS_AUTOID_HASH(false); // Unsupported

    MemberId memberId = 0;
    MinimalStructMember mst_mcap_file_creation_failure;
    mst_mcap_file_creation_failure.common().member_id(memberId++);
    mst_mcap_file_creation_failure.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported
    mst_mcap_file_creation_failure.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported
    mst_mcap_file_creation_failure.common().member_flags().IS_EXTERNAL(false); // Unsupported
    mst_mcap_file_creation_failure.common().member_flags().IS_OPTIONAL(false);
    mst_mcap_file_creation_failure.common().member_flags().IS_MUST_UNDERSTAND(false);
    mst_mcap_file_creation_failure.common().member_flags().IS_KEY(false);
    mst_mcap_file_creation_failure.common().member_flags().IS_DEFAULT(false); // Doesn't apply
    mst_mcap_file_creation_failure.common().member_type_id(*TypeObjectFactory::get_instance()->get_type_identifier(
                "bool", false));


    MD5 mcap_file_creation_failure_hash("mcap_file_creation_failure");
    for (int i = 0; i < 4; ++i)
    {
        mst_mcap_file_creation_failure.detail().name_hash()[i] = mcap_file_creation_failure_hash.digest[i];
    }
    type_object->minimal().struct_type().member_seq().emplace_back(mst_mcap_file_creation_failure);

    MinimalStructMember mst_disk_full;
    mst_disk_full.common().member_id(memberId++);
    mst_disk_full.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported
    mst_disk_full.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported
    mst_disk_full.common().member_flags().IS_EXTERNAL(false); // Unsupported
    mst_disk_full.common().member_flags().IS_OPTIONAL(false);
    mst_disk_full.common().member_flags().IS_MUST_UNDERSTAND(false);
    mst_disk_full.common().member_flags().IS_KEY(false);
    mst_disk_full.common().member_flags().IS_DEFAULT(false); // Doesn't apply
    mst_disk_full.common().member_type_id(*TypeObjectFactory::get_instance()->get_type_identifier("bool", false));


    MD5 disk_full_hash("disk_full");
    for (int i = 0; i < 4; ++i)
    {
        mst_disk_full.detail().name_hash()[i] = disk_full_hash.digest[i];
    }
    type_object->minimal().struct_type().member_seq().emplace_back(mst_disk_full);


    // Header
    // TODO Inheritance
    //type_object->minimal().struct_type().header().base_type()._d(EK_MINIMAL);
    //type_object->minimal().struct_type().header().base_type().equivalence_hash()[0..13];
    TypeIdentifier identifier;
    identifier._d(EK_MINIMAL);

    eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv1);
    size_t current_alignment {0};
    SerializedPayload_t payload(static_cast<uint32_t>(
                calculator.calculate_serialized_size(type_object->minimal().struct_type(), current_alignment) + 4));
    eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size);
    // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document)
    eprosima::fastcdr::Cdr ser(
        fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS,
        eprosima::fastcdr::CdrVersion::XCDRv1); // Object that serializes the data.
    payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;

    ser << *type_object;
#if FASTCDR_VERSION_MAJOR == 1
    payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length
#else
    payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length
#endif // FASTCDR_VERSION_MAJOR == 1
    MD5 objectHash;
    objectHash.update((char*)payload.data, payload.length);
    objectHash.finalize();
    for (int i = 0; i < 14; ++i)
    {
        identifier.equivalence_hash()[i] = objectHash.digest[i];
    }

    TypeObjectFactory::get_instance()->add_type_object("DdsRecorderMonitoringErrorStatus", &identifier, type_object);
    delete type_object;
    return TypeObjectFactory::get_instance()->get_type_object("DdsRecorderMonitoringErrorStatus", false);
}

const TypeObject* GetCompleteDdsRecorderMonitoringErrorStatusObject()
{
    const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object(
        "DdsRecorderMonitoringErrorStatus", true);
    if (c_type_object != nullptr && c_type_object->_d() == EK_COMPLETE)
    {
        return c_type_object;
    }

    TypeObject* type_object = new TypeObject();
    type_object->_d(EK_COMPLETE);
    type_object->complete()._d(TK_STRUCTURE);

    type_object->complete().struct_type().struct_flags().IS_FINAL(false);
    type_object->complete().struct_type().struct_flags().IS_APPENDABLE(false);
    type_object->complete().struct_type().struct_flags().IS_MUTABLE(false);
    type_object->complete().struct_type().struct_flags().IS_NESTED(false);
    type_object->complete().struct_type().struct_flags().IS_AUTOID_HASH(false); // Unsupported

    MemberId memberId = 0;
    CompleteStructMember cst_mcap_file_creation_failure;
    cst_mcap_file_creation_failure.common().member_id(memberId++);
    cst_mcap_file_creation_failure.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported
    cst_mcap_file_creation_failure.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported
    cst_mcap_file_creation_failure.common().member_flags().IS_EXTERNAL(false); // Unsupported
    cst_mcap_file_creation_failure.common().member_flags().IS_OPTIONAL(false);
    cst_mcap_file_creation_failure.common().member_flags().IS_MUST_UNDERSTAND(false);
    cst_mcap_file_creation_failure.common().member_flags().IS_KEY(false);
    cst_mcap_file_creation_failure.common().member_flags().IS_DEFAULT(false); // Doesn't apply
    cst_mcap_file_creation_failure.common().member_type_id(*TypeObjectFactory::get_instance()->get_type_identifier(
                "bool", false));


    cst_mcap_file_creation_failure.detail().name("mcap_file_creation_failure");

    type_object->complete().struct_type().member_seq().emplace_back(cst_mcap_file_creation_failure);

    CompleteStructMember cst_disk_full;
    cst_disk_full.common().member_id(memberId++);
    cst_disk_full.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported
    cst_disk_full.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported
    cst_disk_full.common().member_flags().IS_EXTERNAL(false); // Unsupported
    cst_disk_full.common().member_flags().IS_OPTIONAL(false);
    cst_disk_full.common().member_flags().IS_MUST_UNDERSTAND(false);
    cst_disk_full.common().member_flags().IS_KEY(false);
    cst_disk_full.common().member_flags().IS_DEFAULT(false); // Doesn't apply
    cst_disk_full.common().member_type_id(*TypeObjectFactory::get_instance()->get_type_identifier("bool", false));


    cst_disk_full.detail().name("disk_full");

    type_object->complete().struct_type().member_seq().emplace_back(cst_disk_full);


    // Header
    type_object->complete().struct_type().header().detail().type_name("DdsRecorderMonitoringErrorStatus");
    // TODO inheritance
    TypeIdentifier identifier;
    identifier._d(EK_COMPLETE);

    eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv1);
    size_t current_alignment {0};
    SerializedPayload_t payload(static_cast<uint32_t>(
                calculator.calculate_serialized_size(type_object->complete().struct_type(), current_alignment) + 4));
    eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size);
    // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document)
    eprosima::fastcdr::Cdr ser(
        fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS,
        eprosima::fastcdr::CdrVersion::XCDRv1); // Object that serializes the data.
    payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;

    ser << *type_object;
#if FASTCDR_VERSION_MAJOR == 1
    payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length
#else
    payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length
#endif // FASTCDR_VERSION_MAJOR == 1
    MD5 objectHash;
    objectHash.update((char*)payload.data, payload.length);
    objectHash.finalize();
    for (int i = 0; i < 14; ++i)
    {
        identifier.equivalence_hash()[i] = objectHash.digest[i];
    }

    TypeObjectFactory::get_instance()->add_type_object("DdsRecorderMonitoringErrorStatus", &identifier, type_object);
    delete type_object;
    return TypeObjectFactory::get_instance()->get_type_object("DdsRecorderMonitoringErrorStatus", true);
}

const TypeIdentifier* GetDdsRecorderMonitoringStatusIdentifier(
        bool complete)
{
    const TypeIdentifier* c_identifier = TypeObjectFactory::get_instance()->get_type_identifier(
        "DdsRecorderMonitoringStatus", complete);
    if (c_identifier != nullptr && (!complete || c_identifier->_d() == EK_COMPLETE))
    {
        return c_identifier;
    }

    GetDdsRecorderMonitoringStatusObject(complete); // Generated inside
    return TypeObjectFactory::get_instance()->get_type_identifier("DdsRecorderMonitoringStatus", complete);
}

const TypeObject* GetDdsRecorderMonitoringStatusObject(
        bool complete)
{
    const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("DdsRecorderMonitoringStatus",
                    complete);
    if (c_type_object != nullptr)
    {
        return c_type_object;
    }
    else if (complete)
    {
        return GetCompleteDdsRecorderMonitoringStatusObject();
    }
    //else
    return GetMinimalDdsRecorderMonitoringStatusObject();
}

const TypeObject* GetMinimalDdsRecorderMonitoringStatusObject()
{
    const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("DdsRecorderMonitoringStatus",
                    false);
    if (c_type_object != nullptr)
    {
        return c_type_object;
    }

    TypeObject* type_object = new TypeObject();
    type_object->_d(EK_MINIMAL);
    type_object->minimal()._d(TK_STRUCTURE);

    type_object->minimal().struct_type().struct_flags().IS_FINAL(false);
    type_object->minimal().struct_type().struct_flags().IS_APPENDABLE(false);
    type_object->minimal().struct_type().struct_flags().IS_MUTABLE(false);
    type_object->minimal().struct_type().struct_flags().IS_NESTED(false);
    type_object->minimal().struct_type().struct_flags().IS_AUTOID_HASH(false); // Unsupported

    MemberId memberId = 0;
    MinimalStructMember mst_ddsrecorder_error_status;
    mst_ddsrecorder_error_status.common().member_id(memberId++);
    mst_ddsrecorder_error_status.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported
    mst_ddsrecorder_error_status.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported
    mst_ddsrecorder_error_status.common().member_flags().IS_EXTERNAL(false); // Unsupported
    mst_ddsrecorder_error_status.common().member_flags().IS_OPTIONAL(false);
    mst_ddsrecorder_error_status.common().member_flags().IS_MUST_UNDERSTAND(false);
    mst_ddsrecorder_error_status.common().member_flags().IS_KEY(false);
    mst_ddsrecorder_error_status.common().member_flags().IS_DEFAULT(false); // Doesn't apply
    mst_ddsrecorder_error_status.common().member_type_id(*GetDdsRecorderMonitoringErrorStatusIdentifier(false));

    MD5 ddsrecorder_error_status_hash("ddsrecorder_error_status");
    for (int i = 0; i < 4; ++i)
    {
        mst_ddsrecorder_error_status.detail().name_hash()[i] = ddsrecorder_error_status_hash.digest[i];
    }
    type_object->minimal().struct_type().member_seq().emplace_back(mst_ddsrecorder_error_status);


    // Header
    // TODO Inheritance
    //type_object->minimal().struct_type().header().base_type()._d(EK_MINIMAL);
    //type_object->minimal().struct_type().header().base_type().equivalence_hash()[0..13];
    type_object->minimal().struct_type().header().base_type(*GetMonitoringStatusIdentifier(false));

    TypeIdentifier identifier;
    identifier._d(EK_MINIMAL);

    eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv1);
    size_t current_alignment {0};
    SerializedPayload_t payload(static_cast<uint32_t>(
                calculator.calculate_serialized_size(type_object->minimal().struct_type(), current_alignment) + 4));
    eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size);
    // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document)
    eprosima::fastcdr::Cdr ser(
        fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS,
        eprosima::fastcdr::CdrVersion::XCDRv1); // Object that serializes the data.
    payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;

    ser << *type_object;
#if FASTCDR_VERSION_MAJOR == 1
    payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length
#else
    payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length
#endif // FASTCDR_VERSION_MAJOR == 1
    MD5 objectHash;
    objectHash.update((char*)payload.data, payload.length);
    objectHash.finalize();
    for (int i = 0; i < 14; ++i)
    {
        identifier.equivalence_hash()[i] = objectHash.digest[i];
    }

    TypeObjectFactory::get_instance()->add_type_object("DdsRecorderMonitoringStatus", &identifier, type_object);
    delete type_object;
    return TypeObjectFactory::get_instance()->get_type_object("DdsRecorderMonitoringStatus", false);
}

const TypeObject* GetCompleteDdsRecorderMonitoringStatusObject()
{
    const TypeObject* c_type_object = TypeObjectFactory::get_instance()->get_type_object("DdsRecorderMonitoringStatus",
                    true);
    if (c_type_object != nullptr && c_type_object->_d() == EK_COMPLETE)
    {
        return c_type_object;
    }

    TypeObject* type_object = new TypeObject();
    type_object->_d(EK_COMPLETE);
    type_object->complete()._d(TK_STRUCTURE);

    type_object->complete().struct_type().struct_flags().IS_FINAL(false);
    type_object->complete().struct_type().struct_flags().IS_APPENDABLE(false);
    type_object->complete().struct_type().struct_flags().IS_MUTABLE(false);
    type_object->complete().struct_type().struct_flags().IS_NESTED(false);
    type_object->complete().struct_type().struct_flags().IS_AUTOID_HASH(false); // Unsupported

    MemberId memberId = 0;
    CompleteStructMember cst_ddsrecorder_error_status;
    cst_ddsrecorder_error_status.common().member_id(memberId++);
    cst_ddsrecorder_error_status.common().member_flags().TRY_CONSTRUCT1(false); // Unsupported
    cst_ddsrecorder_error_status.common().member_flags().TRY_CONSTRUCT2(false); // Unsupported
    cst_ddsrecorder_error_status.common().member_flags().IS_EXTERNAL(false); // Unsupported
    cst_ddsrecorder_error_status.common().member_flags().IS_OPTIONAL(false);
    cst_ddsrecorder_error_status.common().member_flags().IS_MUST_UNDERSTAND(false);
    cst_ddsrecorder_error_status.common().member_flags().IS_KEY(false);
    cst_ddsrecorder_error_status.common().member_flags().IS_DEFAULT(false); // Doesn't apply
    cst_ddsrecorder_error_status.common().member_type_id(*GetDdsRecorderMonitoringErrorStatusIdentifier(true));

    cst_ddsrecorder_error_status.detail().name("ddsrecorder_error_status");

    type_object->complete().struct_type().member_seq().emplace_back(cst_ddsrecorder_error_status);


    // Header
    type_object->complete().struct_type().header().detail().type_name("DdsRecorderMonitoringStatus");
    // TODO inheritance
    type_object->complete().struct_type().header().base_type(*GetMonitoringStatusIdentifier(true));

    TypeIdentifier identifier;
    identifier._d(EK_COMPLETE);

    eprosima::fastcdr::CdrSizeCalculator calculator(eprosima::fastcdr::CdrVersion::XCDRv1);
    size_t current_alignment {0};
    SerializedPayload_t payload(static_cast<uint32_t>(
                calculator.calculate_serialized_size(type_object->complete().struct_type(), current_alignment) + 4));
    eprosima::fastcdr::FastBuffer fastbuffer((char*) payload.data, payload.max_size);
    // Fixed endian (Page 221, EquivalenceHash definition of Extensible and Dynamic Topic Types for DDS document)
    eprosima::fastcdr::Cdr ser(
        fastbuffer, eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS,
        eprosima::fastcdr::CdrVersion::XCDRv1); // Object that serializes the data.
    payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;

    ser << *type_object;
#if FASTCDR_VERSION_MAJOR == 1
    payload.length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length
#else
    payload.length = (uint32_t)ser.get_serialized_data_length(); //Get the serialized length
#endif // FASTCDR_VERSION_MAJOR == 1
    MD5 objectHash;
    objectHash.update((char*)payload.data, payload.length);
    objectHash.finalize();
    for (int i = 0; i < 14; ++i)
    {
        identifier.equivalence_hash()[i] = objectHash.digest[i];
    }

    TypeObjectFactory::get_instance()->add_type_object("DdsRecorderMonitoringStatus", &identifier, type_object);
    delete type_object;
    return TypeObjectFactory::get_instance()->get_type_object("DdsRecorderMonitoringStatus", true);
}
